<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8" />
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="viewport" content="width=device-width, initial-scale=1.0" />
        <title>角色上传</title>
        <link rel="stylesheet" type="text/css" href="../../css/aui.css" />
    </head>
    <style>
        .ImgUploadtBody {
            margin: 1rem auto;
            width: 8rem;
            height: 7rem;
        }
    </style>
    <body>
        <header class="aui-bar aui-bar-nav" id="aui-header">
            <div class="aui-pull-left aui-btn" onclick="close_win();">
                <span class="aui-iconfont aui-icon-left"></span>返回
            </div>
            <div class="aui-title" style="left: 2rem; right: 2rem">角色上传</div>
        </header>
        <div class="aui-grid">
            <div class="aui-row">
                <div class="aui-col-xs-3"></div>
                <div class="aui-col-xs-6">
                    <img
                        id="user-info-avatar"
                        src="http://172.16.32.194/setting/8.jpg"
                        alt=""
                        class="ImgUploadtBody"
                        onclick="profile_select();"
                    />
                    <h3>上传已有视频，或者直接拍摄视频上传</h3>
                </div>
            </div>
        </div>
    </body>
</html>
<script>
    var userid = "";
    var ftpRequestTest;
    apiready = function () {
        ftpRequestTest = api.require("ftpRequest");
        userid = api.pageParam.uid;
    };
    function close_win() {
        api.openWin({
            name: "UserNameMain",
            url: "./UserNameMain.html",
            reload: true,
        });
    }
    function profile_select() {
        var perms = new Array();
        perms = ["camera", "library"]; //需要先赋予权限，才能继续进行  如果没有权限就得去更改手机设置
        var rets = api.hasPermission(
            {
                list: perms,
            },
            function (ret, err) {
                alert(JSON.stringify(ret));
                alert(JSON.stringify(err));
            }
        );
        api.actionSheet(
            {
                title: "头像设置",
                cancelTitle: "取消",
                buttons: ["从本机相册选择", "拍摄"],
            },
            function (ret, err) {
                var index = ret.buttonIndex;
                if (index == 1) {
                    api.getPicture(
                        {
                            sourceType: "library",
                            encodingType: "jpg",
                            mediaValue: "pic",
                            destinationType: "base64",
                            allowEdit: true,
                            quality: 100,
                            targetWidth: 1000,
                            targetHeight: 1000,
                            saveToPhotoAlbum: false,
                        },
                        function (ret, err) {
                            var tmp = ret;
                            if (ret.data) {
                                local_avatar_info = ret.data;
                                // $api.byId('user-info-avatar').src = ret.data;
                                var imageCrop = api.require("imageCrop");
                                imageCrop.clipPhoto(
                                    {
                                        imgPath: ret.data,
                                        height: 300,
                                        width: 300,
                                    },
                                    function (ret, err) {
                                        if (ret) {
                                            //console.log(ret.imgPath);
                                            $api.byId("user-info-avatar").src = ret.imgPath;
                                            local_avatar_info = ret.imgPath;
                                        } else {
                                            // alert(JSON.stringify(err));
                                        }
                                    }
                                );
                            } else {
                            }
                        }
                    );
                } else if (index == 2) {
                    api.getPicture(
                        {
                            sourceType: "camera",
                            encodingType: "jpg",
                            mediaValue: "pic",
                            destinationType: "url",
                            allowEdit: true,
                            quality: 100,
                            saveToPhotoAlbum: false,
                        },
                        function (ret, err) {
                            if (ret.data) {
                                local_avatar_info = ret.data;
                                if (ret.data) {
                                    var imageCrop = api.require("imageCrop");
                                    imageCrop.clipPhoto(
                                        {
                                            imgPath: ret.data,
                                            height: 300,
                                            width: 300,
                                        },
                                        function (ret, err) {
                                            if (ret) {
                                                $api.byId("user-info-avatar").src = ret.imgPath;
                                                local_avatar_info = ret.imgPath;
                                            } else {
                                                //alert(JSON.stringify(err));
                                            }
                                        }
                                    );
                                }
                            } else {
                                //alert(JSON.stringify(err));
                            }
                        }
                    );
                }
            }
        );
    }
</script>
